package lesson2.com.biz;


public class Customer  implements Comparable<Customer> {
    
    private String firstName="",lastName="";
    private double creditLimit;
    
    public Customer(){
        this("no first","no last",0.0D);
    }

    public Customer(String firstName, String lastName, double creditLimit) {
        this.firstName = firstName;
        this.lastName = lastName;
        this.creditLimit = creditLimit;
    }
    
    //public int compareTo(Object anotherCust){
     public int compareTo(Customer anotherCust) {
       // if(!(anotherCust instanceof Customer)){
       //     throw new IllegalArgumentException("Can only compare customers to other customers");
       // }
        //Customer other = (Customer)anotherCust;
        int val = this.lastName.compareTo(anotherCust.lastName);
        if(val!=0){
            return val;
        }
        return this.firstName.compareTo(anotherCust.firstName);
    }

    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        if(firstName==null) firstName="";
        this.firstName = firstName;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        if(lastName==null) lastName="";
        this.lastName = lastName;
    }

    public double getCreditLimit() {
        return creditLimit;
    }

    public void setCreditLimit(double creditLimit) {
        if(creditLimit<0.0){
            return;
        }
        this.creditLimit = creditLimit;
    }

    @Override
    public String toString() {
        return "Customer{" + "firstName=" + firstName + ", lastName=" + lastName + ", creditLimit=" + creditLimit + '}';
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 23 * hash + (this.firstName != null ? this.firstName.hashCode() : 0);
        hash = 23 * hash + (this.lastName != null ? this.lastName.hashCode() : 0);
        hash = 23 * hash + (int) (Double.doubleToLongBits(this.creditLimit) ^ (Double.doubleToLongBits(this.creditLimit) >>> 32));
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Customer other = (Customer) obj;
        if ((this.firstName == null) ? (other.firstName != null) : !this.firstName.equals(other.firstName)) {
            return false;
        }
        if ((this.lastName == null) ? (other.lastName != null) : !this.lastName.equals(other.lastName)) {
            return false;
        }
        if (Double.doubleToLongBits(this.creditLimit) != Double.doubleToLongBits(other.creditLimit)) {
            return false;
        }
        return true;
    }

   
    

}